#include<iostream>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<list>
using namespace std;
#include "stack.h"
#include "queue.h"
#include "priority_queue.h"
void Test1()
{
	MyStack::stack<int> st;
	st.push(1);
	st.push(2);
	st.push(3);
	while (!st.empty())
	{
		cout << st.top() << endl;
		st.pop();
	}
}
void Test2()
{
	MyQueue::queue<int> q;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	while (!q.empty())
	{
		cout << q.front() << endl;
		q.pop();
	}
}
void Test3()
{
	Mypriority_queue::priority_queue<int> q; //大根堆
	q.push(2);
	q.push(1);
	q.push(5);
	q.push(3);
	q.push(4);
	while (!q.empty())
	{
		cout << q.top() << " ";
		q.pop();
	}
}
void Test4()
{
	int arr[] = { 1,2,3 };
	Mypriority_queue::priority_queue<int> q(arr, arr + sizeof(arr) / sizeof(int));
	while (!q.empty())
	{
		cout << q.top() << " ";
		q.pop();
	}
}
void Test5()
{
	MyStack::stack<int> st;
	st.push(1);
	st.push(2);
	st.push(3);
	st.push(4);
	MyStack::stack<int> st1(st);
	st1.push(5);
	st1.swap(st);
	while (!st.empty())
	{
		cout << st.top() << " ";
		st.pop();
	}
	cout << endl;
	while (!st1.empty())
	{
		cout << st1.top() << " ";
		st1.pop();
	}
	cout << endl;
}
void Test6()
{
	MyQueue::queue<int> q;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	MyQueue::queue<int> q1(q);
	q1.push(5);
	q1.push(6);
	q.swap(q1);
	while (!q.empty())
	{
		cout << q.front() << " ";
		q.pop();
	}
	cout << endl;
	while (!q1.empty())
	{
		cout << q1.front() << " ";
		q1.pop();
	}
	cout << endl;
}
void Test7()
{
	/*stack<int> st;
	st.push(1);
	st.push(2);
	st.push(3);
	st.push(4);
	while (!st.empty())
	{
		cout << st.top() << " ";
		st.pop();
	}*/

	queue<int> q;
	q.push(1);
	q.push(2);
	q.push(3);
	q.push(4);
	while (!q.empty())
	{
		cout << q.front() << " " << q.back() << endl;
		q.pop();
	}
}
void Test8()
{
	//默认情况下，创建的是大堆
	vector<int> v{ 3,2,7,6,0,4,1,9,8,5 };
	priority_queue<int> q1;
	for (auto& e : v)
	{
		q1.push(e);
	}
	cout << q1.top() << endl;
	
	//如果要创建小堆，将第三个模板参数换成greater比较方式
	priority_queue<int, vector<int>, greater<int>> q2(v.begin(), v.end());
	cout << q2.top() << endl;
}
class Date
{
public:
	Date(int year = 1900, int month = 1, int day = 1)
		: _year(year)
		, _month(month)
		, _day(day)
	{}
	bool operator<(const Date& d)const
	{
		return (_year < d._year) ||
			(_year == d._year && _month < d._month) ||
			(_year == d._year && _month == d._month && _day < d._day);
	}
	bool operator>(const Date& d)const
	{
		return (_year > d._year) ||
			(_year == d._year && _month > d._month) ||
			(_year == d._year && _month == d._month && _day > d._day);
	}
	friend ostream& operator<<(ostream& _cout, const Date& d);
private:
	int _year;
	int _month;
	int _day;
};
ostream& operator<<(ostream& _cout, const Date& d)
{
	_cout << d._year << "-" << d._month << "-" << d._day;
	return _cout;
}
void Test9()
{
	// 大堆，需要用户在自定义类型中提供<的重载
	priority_queue<Date> q1;
	q1.push(Date(2018, 10, 29));
	q1.push(Date(2018, 10, 28));
	q1.push(Date(2018, 10, 30));
	cout << q1.top() << endl;
	// 如果要创建小堆，需要用户提供>的重载
	priority_queue<Date, vector<Date>, greater<Date>> q2;
	q2.push(Date(2018, 10, 29));
	q2.push(Date(2018, 10, 28));
	q2.push(Date(2018, 10, 30));
	cout << q2.top() << endl;
}
void Test10()
{
	vector<int> v{ 4,3,1,2,6 };
	Mypriority_queue::priority_queue<int> q1(v.begin(), v.end());
	cout << q1.top() << endl;
	Mypriority_queue::priority_queue<int> q2(v.begin(), v.begin() + 2);
	cout << q2.top() << endl;
	q1.swap(q2);
	cout << q1.top() << endl;
	cout << q2.top() << endl;
}
namespace GL
{
	template<class T>
	struct less {
		bool operator()(const T& left, const T& right) const
		{
			return left < right;
		}
	};
	template<class T>
	struct greater {
		bool operator()(const T& left, const T& right) const
		{
			return left > right;
		}
	};
}
void Test11()
{
	GL::greater<int> g;
	cout << g(2, 3) << endl;
	GL::less<int> l;
	cout << l(2, 3) << endl;
}
void Test12()
{
	vector<int> v = { 2,3,1,4,7,6,5 };
	Mypriority_queue::priority_queue<int> q1(v.begin(), v.end());
	while (!q1.empty())
	{
		cout << q1.top() << " ";
		q1.pop();
	}
	cout << endl;
	Mypriority_queue::priority_queue<int, vector<int>, Mypriority_queue::greater<int>> q2(v.begin(), v.end());
	while (!q2.empty())
	{
		cout << q2.top() << " ";
		q2.pop();
	}
	cout << endl;
}
struct Less
{
	bool operator()(const Date* d1, const Date* d2)
	{
		return *d1 < *d2;
	}
};
struct Greater
{
	bool operator()(const Date* d1, const Date* d2)
	{
		return *d1 > *d2;
	}
};
void Test13()
{
	Mypriority_queue::priority_queue<Date*, vector<Date*>, Less> q;
	q.push(new Date(2025, 1, 1));
	q.push(new Date(2025, 2, 1));
	q.push(new Date(2025, 3, 1));
	while (!q.empty())
	{
		cout << *q.top() << " ";
		q.pop();
	}
	cout << endl;

	Mypriority_queue::priority_queue<Date*, vector<Date*>, Greater> q1;
	q1.push(new Date(2025, 1, 1));
	q1.push(new Date(2025, 2, 1));
	q1.push(new Date(2025, 3, 1));
	while (!q1.empty())
	{
		cout << *q1.top() << " ";
		q1.pop();
	}
	cout << endl;
}
int main()
{
	//Test1();
	//Test2();
	//Test3();
	//Test4();
	//Test5();
	//Test6();
	//Test7();
	//Test8();
	//Test9();
	//Test10();
	//Test11();
	//Test12();
	Test13();
	return 0;
}